(function() {
    'use strict';

    angular
        .module('zhserverApp')
        .controller('ZhengXiangMingMySuffixDialogController', ZhengXiangMingMySuffixDialogController);

    ZhengXiangMingMySuffixDialogController.$inject = ['$resource','$timeout', '$scope', '$stateParams', '$uibModalInstance', 'entity', 'ZhengXiangMing', 'BingMing'];

    function ZhengXiangMingMySuffixDialogController ($resource,$timeout, $scope, $stateParams, $uibModalInstance, entity, ZhengXiangMing, BingMing) {
        var vm = this;

        vm.zhengXiangMing = entity;
        vm.clear = clear;
        vm.save = save;
        var urlBM= "api/bing-mings/All";
        var zxm_resource=$resource(urlBM);
        zxm_resource.query(function (data) {
            vm.bingmings=data;
        }, function (error) {
            console.log(error.data.message);
        });

        $timeout(function (){
            angular.element('.form-group:eq(1)>input').focus();
        });

        function clear () {
            $uibModalInstance.dismiss('cancel');
        }

        function save () {
            vm.isSaving = true;
            if (vm.zhengXiangMing.id !== null) {
                ZhengXiangMing.update(vm.zhengXiangMing, onSaveSuccess, onSaveError);
            } else {
                ZhengXiangMing.save(vm.zhengXiangMing, onSaveSuccess, onSaveError);
            }
        }

        function onSaveSuccess (result) {
            $scope.$emit('zhserverApp:zhengXiangMingUpdate', result);
            $uibModalInstance.close(result);
            vm.isSaving = false;
        }

        function onSaveError () {
            vm.isSaving = false;
        }


    }
})();
